<!DOCTYPE html>
<html lang="zh-cn">


<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
  <meta name="theme-color" content="#202020"/>
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  
    <meta name="keywords" content="RSA," />
  

  
    <meta name="description" content="我在时间的长河中流浪，寻找一个有你的地方" />
  
  
  
    <link rel="icon" type="image/x-icon" href="https://cdn.jsdelivr.net/gh/haige2486/CDN@1.0/images/favicon.ico">
  
  <title>加密小计 [ 海哥のBlog ]</title>
  
    <!-- stylesheets list from config.yml -->
    
      <link rel="stylesheet" href="//cdn.bootcss.com/pure/1.0.0/pure-min.css">
    
      <link rel="stylesheet" href="/css/xoxo.css">
    
      <link rel="stylesheet" href="/css/keyframe.css">
    
  
  <script src="https://cdn.jsdelivr.net/npm/pjax/pjax.js"></script>
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<meta name="generator" content="Hexo 4.2.0"></head>

<body>
  <div class="nav-container">
    <nav class="home-menu pure-menu pure-menu-horizontal">
  <a class="pure-menu-heading" href="/">
    
      <img class="avatar" src="https://cdn.jsdelivr.net/gh/haige2486/CDN@1.0/images/custom/avatar.png">
    
    <span class="title">海哥のBlog</span>
  </a>

  <ul class="pure-menu-list clearfix">
      
          
            <li class="pure-menu-item"><a href="/" class="pure-menu-link">首页</a></li>
          
      
          
            <li class="pure-menu-item"><a href="/archives" class="pure-menu-link">归档</a></li>
          
      
          
            <li class="pure-menu-item"><a href="/tags" class="pure-menu-link">标签</a></li>
          
      
          
            <li class="pure-menu-item"><a href="/categories" class="pure-menu-link">分类</a></li>
          
      
          
            <li class="pure-menu-item"><a href="/search" class="pure-menu-link">搜索</a></li>
          
      
  </ul>
   
</nav>
  </div>

  <div class="container" id="content-outer">
    <div class="inner" id="content-inner">
      <div class="post-container">
  <article class="post" id="post">
    <header class="post-header text-center">
      <h1 class="title">
        加密小计
      </h1>
      <span>
        
        <time class="time" datetime="2020-06-27T06:51:23.000Z">
          2020-06-27
        </time>
        
      </span>
      
      <span class="slash">/</span>
      <span class="post-meta">
        <span class="post-tags">
          <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/RSA/" rel="tag">RSA</a></li></ul>
        </span>
      </span>
      
      <span class="slash">/</span>
      <span class="read" span id="busuanzi_container_page_pv">
        本文总阅读量：<span id="busuanzi_value_page_pv"></span>次
      </span>
    </header>

    <div class="post-content">
      <h1 id="加密过程"><a href="#加密过程" class="headerlink" title="加密过程"></a>加密过程</h1><p><img src="/images/%E5%8A%A0%E5%AF%86%E8%BF%87%E7%A8%8B.png" alt="加密过程"></p>
<h1 id="国密对应"><a href="#国密对应" class="headerlink" title="国密对应"></a>国密对应</h1><ul>
<li>SM2为基于椭圆曲线密码的公钥密码算法标准，包含数字签名、密钥交换和公钥加密，用于替换RSA / Diffie-Hellman / ECDSA / ECDH 等国际算法。</li>
<li>SM3为密码哈希算法，用于替代MD5 / SHA-1 / SHA-256等国际算法。</li>
<li>SM4为分组密码，用于替代DES / AES等国际算法。</li>
</ul>
<h1 id="对称加密原理"><a href="#对称加密原理" class="headerlink" title="对称加密原理"></a>对称加密原理</h1><p>组织A将明文m通过+e的方式得到密文c，组织B将密文c通过-e的方式得到明文m。这种通过一个密钥加解密（可逆算法的方式）的方式叫对称加密，对称加密的缺点是不能保证密钥分发时的安全性。</p>
<h1 id="非对称加密之RSA加密"><a href="#非对称加密之RSA加密" class="headerlink" title="非对称加密之RSA加密"></a>非对称加密之RSA加密</h1><ul>
<li>找出质数p、q。</li>
<li>n = p x q</li>
<li>f(n) = (p - 1)(q - 1)  <strong>欧拉函数</strong></li>
<li>公钥e为：1 &lt; e &lt; f(n)的数，且e与f(n)互质</li>
<li>私钥d为：e乘d除以f(n)余数为1</li>
<li>加密：明文m的e次方除以n的余数为密文c</li>
<li>解密：密文c的d次方除以n的余数为明文m</li>
</ul>
<p>rsa加密是通过目前的计算量无法将一个大数分解陈两个互质的质数，而这个大数可以通过两个大质数相乘得到。</p>
<p>RSA算法的具体描述如下：</p>
<p>（1）任意选取两个不同的大素数p和q计算乘积</p>
<p><img src="https://bkimg.cdn.bcebos.com/formula/f0dac18152076624d87832b62709895c.svg" alt="img"></p>
<p>（2）任意选取一个大整数e，满足</p>
<p><img src="https://bkimg.cdn.bcebos.com/formula/c33d8c66364a636b051d82f0ee202a36.svg" alt="img"></p>
<p> ，整数e用做加密钥（注意：e的选取是很容易的，例如，所有大于p和q的素数都可用，gcd求最大公约数） </p>
<p>（3）确定的解密钥d，满足</p>
<p><img src="https://bkimg.cdn.bcebos.com/formula/da8649c0078a0a842779394d64011776.svg" alt="img"></p>
<p> ，即</p>
<p><img src="https://bkimg.cdn.bcebos.com/formula/4dee3f4df52a81983db0e3c619f96058.svg" alt="img"></p>
<p> 是一个任意的整数；所以，若知道e和</p>
<p><img src="https://bkimg.cdn.bcebos.com/formula/679e809a0d964785d0aa4cfcb4218742.svg" alt="img"></p>
<p>，则很容易计算出d </p>
<p>（4）公开整数n和e，秘密保存d </p>
<p>（5）将明文m（m&lt;n是一个整数）加密成密文c，加密算法为 </p>
<p><img src="https://bkimg.cdn.bcebos.com/formula/5947116555169dc6fe9e3f5cdf347706.svg" alt="img"></p>
<p>（6）将密文c解密为明文m，解密算法为 </p>
<p><img src="https://bkimg.cdn.bcebos.com/formula/1a8b337167e4d4b2c23855d88ec4c67f.svg" alt="img"></p>
<p>然而只根据n和e（注意：不是p和q）要计算出d是不可能的。因此，任何人都可对明文进行加密，但只有授权用户（知道d）才可对密文解密 。</p>

    </div>

    <div>全文完。</div>
  </article>
  <div class="toc-container">
    
  <div id="toc" class="toc-article">
    <strong class="toc-title">目录</strong>
    <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#加密过程"><span class="toc-text">加密过程</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#国密对应"><span class="toc-text">国密对应</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#对称加密原理"><span class="toc-text">对称加密原理</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#非对称加密之RSA加密"><span class="toc-text">非对称加密之RSA加密</span></a></li></ol>
  </div>


  </div>
</div>

<div class="share" style="width: 100%;">
  <div class="text-center">
    人生若只如初见，何事秋风悲画扇。
  </div> 
</div>

  
    <div class="post-nav">
      <div class="post-nav-item post-nav-next">
        
          <span>〈 </span>
          <a href="/2020/06/25/webpack-setting/" rel="next" title="webpack setting">
          webpack setting
          </a>
        
      </div>
  
      <div class="post-nav-item post-nav-prev">
          
          <a href="/2020/06/28/docker-notes/" rel="prev" title="docker notes">
            docker notes
          </a>
          <span>〉</span>
        
      </div>
    </div>
  

    </div>

    
    <div id="toTop">^</div>
  </div>
  <footer class="footer text-center">
    <div id="bottom-inner">
        <a class="bottom-item" href="https://lustghost.gitee.io">首页</a> |
        <a class="bottom-item" href="https://github.com/haige2486" target="_blank">GitHub</a> |
        <a class="bottom-item" href="https://hexo.io" target="_blank">Powered by hexo</a>
    </div>
</footer>
  

<script>
  var pjax = new Pjax({
    elements: "a",
    selectors: [".inner"]
  });

  document.addEventListener('visibilitychange', function () {
    if (document.visibilityState == 'hidden') {
      normal_title = document.title;
      document.title = 'დ待゜人归ꦿ໊ོﻬ࿐ོ';
    } else document.title = normal_title;
  });

  function rt() {
    var d = document,
      dd = document.documentElement,
      db = document.body,
      top = dd.scrollTop || db.scrollTop,
      step = Math.floor(top / 20);
    (function () {
      top -= step;
      if (top > -step) {
        dd.scrollTop == 0 ? db.scrollTop = top : dd.scrollTop = top;
        setTimeout(arguments.callee, 20);
      }
    })();
  }
  document.getElementById("toTop").addEventListener("click", rt);
  document.addEventListener("scroll", function () {
    var dd = document.documentElement,
      db = document.body,
      top = dd.scrollTop || db.scrollTop
    if (top > (window.innerHeight*0.7)) {
      document.getElementById("toTop").style.display = "block";
      document.getElementsByClassName("nav-container")[0].style.display = "none";
    } else {
      document.getElementById("toTop").style.display = "none";
    }
    if(top<50){
      document.getElementsByClassName("nav-container")[0].style.display = "block";
    }
  })
</script>
  



  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css">
<script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script>
<!-- require MetingJS -->
<script src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js"></script>
<meting-js  id="2660651585"  server="netease"  type="playlist"  fixed="true"  autoplay="false"  loop="all"  order="random"  preload="auto"  volume="0.7"  mutex="true"  </meting-js>
    <style id="rewrite">
        .aplayer.aplayer-fixed{
            width: 70%;
        }
        .aplayer-body{
            width: 80% !important;
        }
        .aplayer.aplayer-narrow .aplayer-body {
            left: -66px !important;
        }
        .aplayer.aplayer-fixed .lrc-show {
            display: block;
            background: rgba(255, 255, 255, 0.8);
        }
        .aplayer-lrc-current{
            animation: shake-it .5s reverse infinite cubic-bezier(0.68, -0.55, 0.27, 1.55);
        }
    </style>
    <script>
        typeof document.getElementsByClassName("aplayer")[0] !== "undefined" && document.getElementsByClassName("aplayer")[0].addEventListener("click", function () {
            if (document.getElementsByClassName("aplayer-button")[0].hasClass('aplayer-play')) {
                document.getElementsByClassName('aplayer-lrc')[0].removeClass('lrc-show');
            } else {
                document.getElementsByClassName('aplayer-lrc')[0].addClass('lrc-show');
            }
        })
    </script>
</body>
</html>
